package json;

import org.json.JSONArray;
import org.json.JSONObject;

public class TestJson1 {
	public static void main(String[] args) throws Exception {
		String json = "{\"imsi\":\"xxxx\",\"imei\":\"xxxx\",\"id\":\"imei+timestamp\",\"log\":[{\"timestamp\":1234566,\"eventid\":\"appstart\"}]}";
		parseJson(json);
	}
	
	public static void parseJson(String str) throws Exception{
		 JSONObject jsonObject = new JSONObject(str);
         String imsi = jsonObject.getString("imsi");
         String imei = jsonObject.getString("imei");
         JSONArray logsAry = jsonObject.getJSONArray("log");
         if (logsAry != null && logsAry.length() > 0)
         {
             for (int i = 0, len = logsAry.length(); i < len; i++)
             {
                 JSONObject jsonObj = logsAry.getJSONObject(i);
                 String timestamp = jsonObj.getString("timestamp");
                 System.out.println(timestamp);
             }
         }
	}
}
